package hiq.optics.common;

import hiq.math.complex.Complex;

import java.io.FileNotFoundException;
import java.io.PrintWriter;

public abstract class Scalar2DProblem extends Optical2DProblem{
	
	protected static String OBJ_PATH   = "object.dat";
	protected static String TRANS_PATH = "transf.dat";
	
	protected double z;
	protected double ds;
	
	protected double  [][] U0;
	protected Complex [][] U;
	
	@Override
	public void export() {
		try {
			exportObject();
			exportResult();
		} catch (FileNotFoundException e) {
			System.out.println("FILE NOT FOUND EXCEPTION!");
			e.printStackTrace();
		}
		
	}

	// exporting the result picture (absolute value)
	private void exportResult() throws FileNotFoundException {
		PrintWriter pw = new PrintWriter(Scalar2DProblem.TRANS_PATH);
		
		int n = U.length;
		int m = U[0].length;
		
		for (int i=0; i<n; i++){
			for (int j=0; j<m; j++){
				pw.print(U[i][j].abs() + ", ");
			}
			pw.println();
		}		
	}

	// exporting the input picture
	private void exportObject() throws FileNotFoundException {
		PrintWriter pw = new PrintWriter(Scalar2DProblem.OBJ_PATH);
		
		int n = U0.length;
		int m = U0[0].length;
		
		for (int i=0; i<n; i++){
			for (int j=0; j<m; j++){
				pw.print(U0[i][j] + ", ");
			}
			pw.println();
		}
	}
	
	protected int fl(double z){
		return (int)Math.floor(z / ds + 0.5);
	}
	
}
